package com.dependencies.validation.controller;

import com.dependencies.validation.model.User;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhizhou   2024/7/28 15:45
 */
@RestController
@RequestMapping("/users")
@Validated
public class UserController {
    
    @PostMapping
    public ResponseEntity<String> createUser(@Valid @RequestBody User user) {
        //这里通常你可以定制逻辑 保存用户信息导数据库 咱就不延展了 重点看validation功能
        return ResponseEntity.ok("User is valid");
    }
    
    @GetMapping("/{id}")
    public ResponseEntity<User> getUser(@PathVariable @Min(119) Integer id) {
        // 这里咱们就下发一个demo数据好了
        User user = new User();
        user.setId(id);
        user.setName("ZhiZhou");
        user.setEmail("ZhiZhou@iamcoder.com");
        return ResponseEntity.ok(user);
    }
}
